package com.servertest1;

import java.text.DecimalFormat;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ProfileScreen extends Activity implements OnClickListener{
	
	private Button back;
	
	private TextView textwins, textlosses, textties, textpercent, textgames, texthighest, textplayer;
	
	private Client client;
	
	private String[] profileScreen;
	
	private DatabaseHelper checker;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.profilescreen);
		
		Bundle extras = getIntent().getExtras();
		//gamePosition = extras.getInt("position");
		//your_turn_games = (ArrayList<Game>) extras.get("your_turn_games");
		profileScreen = extras.getStringArray("profile_screen_data");
		back = (Button) findViewById(R.id.backbutton);
		back.setOnClickListener(this);
		
		textwins = (TextView) findViewById(R.id.textwins);
		textlosses = (TextView) findViewById(R.id.textlosses);
		textties = (TextView) findViewById(R.id.textties);
		textpercent = (TextView) findViewById(R.id.textpercent);
		texthighest = (TextView) findViewById(R.id.texthighest);
		textgames = (TextView) findViewById(R.id.textgames);
		textplayer = (TextView) findViewById(R.id.textplayer);
		
		int wins = Integer.parseInt(profileScreen[1]);
		int losses = Integer.parseInt(profileScreen[2]);
		int ties = Integer.parseInt(profileScreen[3]);
		
		int total = wins + losses + ties;
		double percent = 0.0;
		System.out.println("testing");
		DecimalFormat df = new DecimalFormat("#.##");
		if(total != 0)
			percent = ((double)wins / total) * 100;
		
		System.out.println(percent);
		textplayer.setText(profileScreen[0]);
		textwins.setText(profileScreen[1]);
		textlosses.setText(profileScreen[2]);
		textties.setText(profileScreen[3]);
		textpercent.setText(df.format(percent));
		//texthighest.setText(profileScreen[4]);
		textgames.setText(Integer.toString(total));
		
	}

	public void onClick(View v) {
		switch (v.getId())
		{
		case R.id.backbutton:
				Intent goBack = new Intent();
				setResult(RESULT_OK, goBack);
				finish();
			break;
		default:
			break;
		}
		
	}
	
}
